if (DEFINED target_strip_included)
  return()
endif()

set(target_strip_included)

message(STATUS "strip ${CMAKE_STRIP}")
message(STATUS "objcopy ${CMAKE_OBJCOPY}")

option(ENABLE_STRIP UNIX)

if (ENABLE_STRIP)
  macro(target_strip TARGET)
    add_custom_command(
            TARGET ${TARGET} POST_BUILD
            COMMAND ${CMAKE_OBJCOPY} --only-keep-debug "$<TARGET_FILE:${TARGET}>" "$<TARGET_FILE:${TARGET}>.debug"
            COMMAND ${CMAKE_OBJCOPY} --strip-debug "$<TARGET_FILE:${TARGET}>"
            COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink="$<TARGET_FILE:${TARGET}>.debug" "$<TARGET_FILE:${TARGET}>"
            COMMENT "Strip target ${TARGET}"
    )
  endmacro()
else()
  macro(target_strip)
  endmacro()
endif()
